package com.itic.mobile.ffmpeg;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.utils.FfmpegWindowUtils;
import com.itic.appbase.framework.utils.IdGen;
import com.itic.mobile.base.BaseMobileInterface;


/**
 * 京东联盟
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/mobile/ffmpeg")
public class FfmpegInterface
     extends BaseMobileInterface {
	
	
	/**
	 *根据视频URL获取封面
	 */
	@RequestMapping(value = "/getVideoCoverPic")
	@ResponseBody
	public String getVideoCoverPic( HttpServletRequest request, HttpServletResponse response, String videoUrl ) {
		String namepng = IdGen.uuid();
		String videoImg = "http://develop.huifakeji.com/ffmpeg/"+namepng+".png";
		try{
			
        	String ffmpeg_path = "D:/xampp/htdocs/ffmpeg/ffmpeg.exe";
        	String picPath = "D:/xampp/htdocs/ffmpeg/"+namepng+".png";
        	
        	if( !FfmpegWindowUtils.VideoToPicture(FfmpegWindowUtils.saveFileFromUrl(videoUrl, "D:/xampp/htdocs/ffmpeg/"), ffmpeg_path, picPath) ){
        		videoImg = "http://develop.huifakeji.com/ffmpeg/fail.png";
        	}
        	
		}catch (Exception e) {
			logException("FfmpegInterface", "getVideoCoverPic", e.toString(), "根据视频获取封面", e);
		}
		return videoImg;
	}
	
	
	/**
	 *根据视频URL获取封面
	 */
	@RequestMapping(value = "/createPoster")
	@ResponseBody
	public String createPoster( HttpServletRequest request, HttpServletResponse response, String image, String url ){
		String namepng = IdGen.uuid();
		String videoImg = "http://develop.jhjvip.cn/ffmpeg/"+namepng+".png";
		try{
			
        	String ffmpeg_path = "C:/develop/zentao/xampp/htdocs/ffmpeg/ffmpeg.exe";
        	String picPath = "C:/develop/zentao/xampp/htdocs/ffmpeg/"+namepng+".png";
        	
        	if( !FfmpegWindowUtils.VideoToPicture(FfmpegWindowUtils.saveFileFromUrl(image, "C:/develop/zentao/xampp/htdocs/ffmpeg/"), ffmpeg_path, picPath) ){
        		videoImg = "http://develop.jhjvip.cn/ffmpeg/fail.png";
        	}
        	
		}catch (Exception e) {
			logException("FfmpegInterface", "createPoster", e.toString(), "合成商品二维码海报", e);
		}
		return videoImg;
	}
	
	
	/**
	 *根据视频URL获取封面
	 */
	@RequestMapping(value = "/inviteVip")
	@ResponseBody
	public String inviteVip( HttpServletRequest request, HttpServletResponse response, String image, String url ){
		String namepng = IdGen.uuid();
		String videoImg = "http://develop.jhjvip.cn/ffmpeg/"+namepng+".png";
		try{
			
        	String ffmpeg_path = "C:/develop/zentao/xampp/htdocs/ffmpeg/ffmpeg.exe";
        	String picPath = "C:/develop/zentao/xampp/htdocs/ffmpeg/"+namepng+".png";
        	
        	if( !FfmpegWindowUtils.VideoToPicture(FfmpegWindowUtils.saveFileFromUrl(image, "C:/develop/zentao/xampp/htdocs/ffmpeg/"), ffmpeg_path, picPath) ){
        		videoImg = "http://develop.jhjvip.cn/ffmpeg/fail.png";
        	}
        	
		}catch (Exception e) {
			logException("FfmpegInterface", "createPoster", e.toString(), "合成商品二维码海报", e);
		}
		return videoImg;
	}
	
	/**
	 *根据视频URL获取封面
	 */
	@RequestMapping(value = "/inviteYun")
	@ResponseBody
	public String inviteYun( HttpServletRequest request, HttpServletResponse response, String image, String url ){
		String namepng = IdGen.uuid();
		String videoImg = "http://develop.jhjvip.cn/ffmpeg/"+namepng+".png";
		try{
			
        	String ffmpeg_path = "C:/develop/zentao/xampp/htdocs/ffmpeg/ffmpeg.exe";
        	String picPath = "C:/develop/zentao/xampp/htdocs/ffmpeg/"+namepng+".png";
        	
        	if( !FfmpegWindowUtils.VideoToPicture(FfmpegWindowUtils.saveFileFromUrl(image, "C:/develop/zentao/xampp/htdocs/ffmpeg/"), ffmpeg_path, picPath) ){
        		videoImg = "http://develop.jhjvip.cn/ffmpeg/fail.png";
        	}
        	
		}catch (Exception e) {
			logException("FfmpegInterface", "createPoster", e.toString(), "合成商品二维码海报", e);
		}
		return videoImg;
	}
	
}